<!-- 首页 -->

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title></title>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery-3.2.1.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/index.css" rel="stylesheet" />
		<script type="text/javascript" charset="utf-8">
			mui.init({
				pullRefresh: {
					container: "#wrap-panel", //下拉刷新容器标识，querySelector能定位的css选择器均可，比如：id、.class等
					down: {
						style: 'circle', //必选，下拉刷新样式，目前支持原生5+ ‘circle’ 样式
						color: '#55aaff', //可选，默认“#2BD009” 下拉刷新控件颜色
						height: '50px', //可选,默认50px.下拉刷新控件的高度,
						range: '100px', //可选 默认100px,控件可下拉拖拽的范围
						offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
						auto: false, //可选,默认false.首次加载自动上拉刷新一次
						callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
							getNav.getNavInfo();
							getAd.getAdInfo();
							getFunction.getFunctionInfo();
							getPromo.getPromoInfo();
							getItem.getItemInfo();
							getBottomNav.getBottomNavInfo();
							mui.toast("已刷新");
							setTimeout("mui('#wrap-panel').pullRefresh().endPulldownToRefresh()", 1000);
						}
					}
				}
			})

			var backButtonPress = 0;
			mui.back = function() {
				backButtonPress++;
				if (backButtonPress > 1) {
					//如果当前用户登录则监控其退出
					if (user.userId != null) {
						//向服务器发送请求
						$.ajax({
							url: "http://39.98.158.247:8040/user/logout",
							dataType: "json",
							type: "POST",
							data: {
								"_method": "PUT",
								"user_id": localStorage.getItem("user"),
							},
							contentType: "application/x-www-form-urlencoded",
							xhrFields: {
								withCredentials: true
							},
							//请求成功时
							success: function(data) {
								console.log(data);
							},
							//请求发生错误
							error: function() {
								console.log("request error");
							},
						})
					}
					localStorage.clear();
					plus.runtime.quit();
				} else {
					plus.nativeUI.toast('再按一次退出应用');
				}
				//这里必须有延迟恢复机制
				setTimeout(function() {
					backButtonPress = 0;
				}, 2000);
				return false;
			}
		</script>
		<script src="js/user.js"></script>
		<script src="js/index-action.js"></script>
	</head>
	<body>

		<header class="mui-bar mui-bar-nav">
			<!-- 顶部搜索框 -->
			<div>
				<div class="mui-input-row mui-search">
					<input type="search" id="search" class="mui-input-clear" value="搜索你要的商品" style="color:#AAAAAA;text-align: center;">
				</div>
			</div>
			<!-- 可滑动导航 -->
			<div id="mynav" class="mui-scroll-wrapper  mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">

				</div>
			</div>
		</header>

		<!-- 底部导航 -->
		<nav class="mui-bar mui-bar-tab" id="nav">

		</nav>
		<div id="wrap-panel">
			<!-- 中心内容展示区 -->
			<div class="mui-content" id="content">

			</div>
		</div>

		<script src="js/search.js"></script>
	</body>
	<script>
		mui('nav').on('tap', 'a', function() {
			document.location.href = this.href;
		})
		mui('.mui-scroll-wrapper').scroll({
			scrollY: false, //是否竖向滚动
			scrollX: true, //是否横向滚动
			deceleration: 0.0006, //阻尼系数,系数越小滑动越灵敏
			bounce: true //是否启用回弹
		});
	</script>

</html>
